package com.nineclock.doc.service.impl;

import com.nineclock.common.enums.ResponseEnum;
import com.nineclock.common.exception.NcException;
import com.nineclock.common.threadlocal.CurrentUserHolder;
import com.nineclock.common.utils.BeanHelper;
import com.nineclock.doc.controller.FolderController;
import com.nineclock.doc.dto.DocFolderDto;
import com.nineclock.doc.mapper.FolderControllerMapper;
import com.nineclock.doc.pojo.DocFolder;
import com.nineclock.doc.service.FolderControllerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@Slf4j
public class FolderControllerServiceImpl implements FolderControllerService {

    @Autowired
    FolderControllerMapper folderControllerMapper;
    @Override
    public void addFolder(DocFolderDto docFolderDto) {
        DocFolder docFolder1 = BeanHelper.copyProperties(docFolderDto, DocFolder.class);
        docFolder1.setCompanyId(CurrentUserHolder.get().getCompanyId());
        docFolder1.setCreateUserId(CurrentUserHolder.get().getCompanyUserId());
        docFolder1.setCreateTime(new Date());
        docFolder1.setOrderNum(0);
        docFolder1.setStatus((short)1);
        int insert = folderControllerMapper.insert(docFolder1);
        if (insert!=1){
            throw new NcException(ResponseEnum.INSERT_OPERATION_FAIL);
        }
    }
}
